package edu.bu.cs673.superkids123.common.controller;

import edu.bu.cs673.superkids123.AbstractController;
import edu.bu.cs673.superkids123.AbstractFrame;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import sun.misc.BASE64Encoder;

public class PasswordController extends AbstractController {

	public PasswordController(AbstractFrame mainFrame) {
		super(mainFrame);
	}

	public static String encrypt(String plaintext) {
		
		MessageDigest md = null;
		
		try {
			md = MessageDigest.getInstance("SHA");
		} catch (NoSuchAlgorithmException e) {
			// TODO: error
		}
		try {
			md.update(plaintext.getBytes("UTF-8"));
		} catch (UnsupportedEncodingException e) {
			// TODO: error
		}

		byte raw[] = md.digest();
		String hash = (new BASE64Encoder()).encode(raw);
		
		return hash;
	}
}
